<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Crafty - Crafty.math.Vector2D</title>
	<link type="text/css" rel="stylesheet" href="/craftyjs-site.css" />

	<link href='http://fonts.googleapis.com/css?family=Arvo:regular,bold' rel='stylesheet' 	type='text/css'>
	<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600' rel='stylesheet' type='text/css'>
	<link rel="shortcut icon" href="/favicon.ico">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
	<link rel="stylesheet" href="/github.css"/>
	<script type="text/javascript">

		var _gaq = _gaq || [];
		_gaq.push(['_setAccount', 'UA-23935213-2']);
		_gaq.push(['_trackPageview']);

		(function () {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();

	</script>
</head>
<body>
	<div id = "header-background"> </div>
	<div id = "page-frame">
	<div id="header">
		<nav class="navbar">
  			<div class="container-fluid">
  				<div class="navbar-header">
  					<a class="navbar-brand" href="/"> <img class="logo" src="/images/text-logo.png" /> </a>
  					
				</div>
				<div class="collapse navbar-collapse navbar-right" id="bs-example-navbar-collapse-1">
					<ul class="nav navbar-nav">
						<li><a href="/">Home</a></li>
						<li><a href="/getting-started/">Getting started</a></li>
						<li><a href="/documentation/">Documentation</a></li>
						<li><a href="/api/">API</a></li>
						<li><a href="https://groups.google.com/forum/#!forum/craftyjs">Forum</a></li>
						<li><a href="/components/">Components</a></li>
						<li class="emph"><a href="/#install">Download</a></li>
					</ul>
				</div>
			</div>
		</nav>
	</div>


	<div id="main">
		<div id="content" class="container">
			



<div id="docs"><div class="toc-holder" id="doc-nav"><ul id="doc-level-one"><li><a href="events.html">List of Events</a></li><li class="category">Core<ul class="category-list"><li><a href="Crafty.html">Crafty</a></li><li><a href="Crafty Core.html">Crafty Core</a></li><li><a href="Crafty-bind.html">Crafty.bind()</a></li><li><a href="Crafty-c.html">Crafty.c()</a></li><li><a href="Crafty-clone.html">Crafty.clone()</a></li><li><a href="Crafty-defineField.html">Crafty.defineField()</a></li><li><a href="Crafty-e.html">Crafty.e()</a></li><li><a href="Crafty-extend.html">Crafty.extend()</a></li><li><a href="Crafty-frame.html">Crafty.frame()</a></li><li><a href="Crafty-getVersion.html">Crafty.getVersion()</a></li><li><a href="Crafty-init.html">Crafty.init()</a></li><li><a href="Crafty-isPaused.html">Crafty.isPaused()</a></li><li><a href="Crafty-one.html">Crafty.one()</a></li><li><a href="Crafty-pause.html">Crafty.pause()</a></li><li><a href="Crafty-s.html">Crafty.s()</a></li><li><a href="Crafty-settings.html">Crafty.settings</a></li><li><a href="Crafty-stage.html">Crafty.stage</a></li><li><a href="Crafty-stop.html">Crafty.stop()</a></li><li><a href="Crafty-support.html">Crafty.support</a></li><li><a href="Crafty-trigger.html">Crafty.trigger()</a></li><li><a href="Crafty-unbind.html">Crafty.unbind()</a></li><li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind()</a></li></ul></li><li class="category">2D<ul class="category-list"><li><a href="2D.html">2D</a></li><li><a href="AngularMotion.html">AngularMotion</a></li><li><a href="Collision.html">Collision</a></li><li><a href="Crafty-circle.html">Crafty.circle</a></li><li><a href="Crafty-diamondIso.html">Crafty.diamondIso</a></li><li><a href="Crafty-HashMap.html">Crafty.HashMap</a></li><li><a href="Crafty-isometric.html">Crafty.isometric</a></li><li><a href="Crafty-map.html">Crafty.map</a></li><li><a href="Crafty-math-Matrix2D.html">Crafty.math.Matrix2D</a></li><li><a href="Crafty-math-Vector2D.html">Crafty.math.Vector2D</a></li><li><a href="Crafty-polygon.html">Crafty.polygon</a></li><li><a href="Crafty-raycast.html">Crafty.raycast()</a></li><li><a href="Crafty-rectManager.html">Crafty.rectManager</a></li><li><a href="Gravity.html">Gravity</a></li><li><a href="GroundAttacher.html">GroundAttacher</a></li><li><a href="Motion.html">Motion</a></li><li><a href="Supportable.html">Supportable</a></li></ul></li><li class="category">Animation<ul class="category-list"><li><a href="Crafty-easing.html">Crafty.easing</a></li><li><a href="SpriteAnimation.html">SpriteAnimation</a></li><li><a href="Tween.html">Tween</a></li></ul></li><li class="category">Assets<ul class="category-list"><li><a href="Crafty-asset.html">Crafty.asset()</a></li><li><a href="Crafty-assets.html">Crafty.assets</a></li><li><a href="Crafty-imageWhitelist.html">Crafty.imageWhitelist()</a></li><li><a href="Crafty-load.html">Crafty.load()</a></li><li><a href="Crafty-paths.html">Crafty.paths()</a></li><li><a href="Crafty-removeAssets.html">Crafty.removeAssets()</a></li></ul></li><li class="category">Audio<ul class="category-list"><li><a href="Crafty-audio.html">Crafty.audio</a></li></ul></li><li class="category">Controls<ul class="category-list"><li><a href="Controllable.html">Controllable</a></li><li><a href="Controls.html">Controls</a></li><li><a href="Draggable.html">Draggable</a></li><li><a href="Fourway.html">Fourway</a></li><li><a href="Jumper.html">Jumper</a></li><li><a href="Multiway.html">Multiway</a></li><li><a href="Twoway.html">Twoway</a></li></ul></li><li class="category">Debug<ul class="category-list"><li><a href="Crafty-error.html">Crafty.error()</a></li><li><a href="Crafty-log.html">Crafty.log()</a></li><li><a href="DebugCanvas.html">DebugCanvas</a></li><li><a href="DebugPolygon.html">DebugPolygon</a></li><li><a href="DebugRectangle.html">DebugRectangle</a></li><li><a href="SolidAreaMap.html">SolidAreaMap</a></li><li><a href="SolidHitBox.html">SolidHitBox</a></li><li><a href="VisibleMBR.html">VisibleMBR</a></li><li><a href="WiredAreaMap.html">WiredAreaMap</a></li><li><a href="WiredHitBox.html">WiredHitBox</a></li></ul></li><li class="category">Events<ul class="category-list"><li><a href="Crafty-addEvent.html">Crafty.addEvent()</a></li><li><a href="Crafty-bind.html">Crafty.bind()</a></li><li><a href="Crafty-one.html">Crafty.one()</a></li><li><a href="Crafty-removeEvent.html">Crafty.removeEvent()</a></li><li><a href="Crafty-trigger.html">Crafty.trigger()</a></li><li><a href="Crafty-unbind.html">Crafty.unbind()</a></li><li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind()</a></li></ul></li><li class="category">Game Loop<ul class="category-list"><li><a href="Crafty-timer.html">Crafty.timer</a></li></ul></li><li class="category">Graphics<ul class="category-list"><li><a href="Canvas.html">Canvas</a></li><li><a href="CanvasLayer.html">CanvasLayer</a></li><li><a href="Color.html">Color</a></li><li><a href="Crafty-assignColor.html">Crafty.assignColor()</a></li><li><a href="Crafty-background.html">Crafty.background()</a></li><li><a href="Crafty-createLayer.html">Crafty.createLayer()</a></li><li><a href="Crafty-defaultShader.html">Crafty.defaultShader()</a></li><li><a href="Crafty-domHelper.html">Crafty.domHelper</a></li><li><a href="Crafty-pixelart.html">Crafty.pixelart()</a></li><li><a href="Crafty-sprite.html">Crafty.sprite()</a></li><li><a href="Crafty-WebGLShader.html">Crafty.WebGLShader()</a></li><li><a href="DOM.html">DOM</a></li><li><a href="DomLayer.html">DomLayer</a></li><li><a href="HTML.html">HTML</a></li><li><a href="Image.html">Image</a></li><li><a href="Particles.html">Particles</a></li><li><a href="Renderable.html">Renderable</a></li><li><a href="Sprite.html">Sprite</a></li><li><a href="Text.html">Text</a></li><li><a href="WebGL.html">WebGL</a></li><li><a href="WebGLLayer.html">WebGLLayer</a></li></ul></li><li class="category">Input<ul class="category-list"><li><a href="AreaMap.html">AreaMap</a></li><li><a href="Button.html">Button</a></li><li><a href="Crafty-findPointerEventTargetByComponent.html">Crafty.findPointerEventTargetByComponent()</a></li><li><a href="Crafty-keyboardDispatch.html">Crafty.keyboardDispatch()</a></li><li><a href="Crafty-keydown.html">Crafty.keydown</a></li><li><a href="Crafty-keys.html">Crafty.keys</a></li><li><a href="Crafty-lastEvent.html">Crafty.lastEvent</a></li><li><a href="Crafty-mouseButtons.html">Crafty.mouseButtons</a></li><li><a href="Crafty-mouseDispatch.html">Crafty.mouseDispatch()</a></li><li><a href="Crafty-mouseWheelDispatch.html">Crafty.mouseWheelDispatch()</a></li><li><a href="Crafty-multitouch.html">Crafty.multitouch()</a></li><li><a href="Crafty-selected.html">Crafty.selected</a></li><li><a href="Crafty-touchDispatch.html">Crafty.touchDispatch()</a></li><li><a href="Keyboard.html">Keyboard</a></li><li><a href="Mouse.html">Mouse</a></li><li><a href="MouseDrag.html">MouseDrag</a></li><li><a href="Touch.html">Touch</a></li></ul></li><li class="category">Misc<ul class="category-list"><li><a href="Crafty-addEvent.html">Crafty.addEvent()</a></li><li><a href="Crafty-device.html">Crafty.device</a></li><li><a href="Crafty-removeEvent.html">Crafty.removeEvent()</a></li><li><a href="Crafty-support.html">Crafty.support</a></li></ul></li><li class="category">Model<ul class="category-list"><li><a href="Model.html">Model</a></li></ul></li><li class="category">Scenes<ul class="category-list"><li><a href="Crafty-scene.html">Crafty.scene()</a></li></ul></li><li class="category">Stage<ul class="category-list"><li><a href="Crafty-background.html">Crafty.background()</a></li><li><a href="Crafty-scene.html">Crafty.scene()</a></li><li><a href="Crafty-viewport.html">Crafty.viewport</a></li></ul></li><li class="category">Utilities<ul class="category-list"><li><a href="Crafty-math.html">Crafty.math</a></li><li><a href="Delay.html">Delay</a></li><li><a href="Storage.html">Storage</a></li></ul></li></ul></div><div id="doc-content" class="doc-page-holder"><div class="doc-page"><h1>Crafty.math.Vector2D <span class="page-badge">Class</span></h1><div class="doclet" id="Crafty-math-Vector2D"><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L238-L254">src/spatial/math.js#L238-L254</a></div><span class="markdown"><p>Vector2D uses the following form:</p>
<x, y>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Number</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Number</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D|Number=0} x </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Number=0} y </dt><dd><span class="markdown"></span></dd></dl></div></div><div><h4>Methods</h4><ul class="page-toc"><li><a href="#-add">.add()</a></li><li><a href="#-angleBetween">.angleBetween()</a></li><li><a href="#-angleTo">.angleTo()</a></li><li><a href="#-clone">.clone()</a></li><li><a href="#-crossProduct">.crossProduct()</a></li><li><a href="#-distance">.distance()</a></li><li><a href="#-distanceSq">.distanceSq()</a></li><li><a href="#-divide">.divide()</a></li><li><a href="#-dotProduct">.dotProduct()</a></li><li><a href="#-equals">.equals()</a></li><li><a href="#-getNormal">.getNormal()</a></li><li><a href="#-isZero">.isZero()</a></li><li><a href="#-magnitude">.magnitude()</a></li><li><a href="#-magnitudeSq">.magnitudeSq()</a></li><li><a href="#-multiply">.multiply()</a></li><li><a href="#-negate">.negate()</a></li><li><a href="#-normalize">.normalize()</a></li><li><a href="#-perpendicular">.perpendicular()</a></li><li><a href="#-scale">.scale()</a></li><li><a href="#-scaleToMagnitude">.scaleToMagnitude()</a></li><li><a href="#-setValues">.setValues()</a></li><li><a href="#-subtract">.subtract()</a></li><li><a href="#-toString">.toString()</a></li><li><a href="#-translate">.translate()</a></li><li><a href="#-tripleProduct">.tripleProduct()</a></li></ul><div class="doclet" id="-add"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.add()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L270-L282">src/spatial/math.js#L270-L282</a></div><span class="markdown"><p>Adds the passed vector to this vector</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">add</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} this after adding</p>
</span></dd></dl></div></div><div class="doclet" id="-angleBetween"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.angleBetween()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L289-L302">src/spatial/math.js#L289-L302</a></div><span class="markdown"><p>Calculates the angle between the passed vector and this vector, using <0,0> as the point of reference.
Angles returned have the range (−π, π].</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">angleBetween</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} the angle between the two vectors in radians</p>
</span></dd></dl></div></div><div class="doclet" id="-angleTo"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.angleTo()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L307-L319">src/spatial/math.js#L307-L319</a></div><span class="markdown"><p>Calculates the angle to the passed vector from this vector, using this vector as the point of reference.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">angleTo</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} the angle to the passed vector in radians</p>
</span></dd></dl></div></div><div class="doclet" id="-clone"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.clone()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L324-L335">src/spatial/math.js#L324-L335</a></div><span class="markdown"><p>Creates and exact, numeric copy of this vector</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">clone</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} the new vector</p>
</span></dd></dl></div></div><div class="doclet" id="-crossProduct"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.crossProduct()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L412-L424">src/spatial/math.js#L412-L424</a></div><span class="markdown"><p>Calculates the z component of the cross product of the two vectors augmented to 3D.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">crossProduct</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} the resultant cross product</p>
</span></dd></dl></div></div><div class="doclet" id="-distance"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.distance()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L340-L352">src/spatial/math.js#L340-L352</a></div><span class="markdown"><p>Calculates the distance from this vector to the passed vector.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">distance</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} the distance between the two vectors</p>
</span></dd></dl></div></div><div class="doclet" id="-distanceSq"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.distanceSq()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L357-L371">src/spatial/math.js#L357-L371</a></div><span class="markdown"><p>Calculates the squared distance from this vector to the passed vector.
This function avoids calculating the square root, thus being slightly faster than .distance( ).</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">distanceSq</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} the squared distance between the two vectors</p>
</span></dd></dl></div><div><h4>See Also</h4><ul class="see-also-list"><li><a href="#-distance">.distance</a></li></ul></div></div><div class="doclet" id="-divide"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.divide()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L376-L388">src/spatial/math.js#L376-L388</a></div><span class="markdown"><p>Divides this vector by the passed vector.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">divide</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} this vector after dividing</p>
</span></dd></dl></div></div><div class="doclet" id="-dotProduct"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.dotProduct()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L395-L407">src/spatial/math.js#L395-L407</a></div><span class="markdown"><p>Calculates the dot product of this and the passed vectors</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">dotProduct</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} the resultant dot product</p>
</span></dd></dl></div></div><div class="doclet" id="-equals"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.equals()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L429-L441">src/spatial/math.js#L429-L441</a></div><span class="markdown"><p>Determines if this vector is numerically equivalent to the passed vector.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Boolean} </span><span class="sig-noun">equals</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Boolean} true if the vectors are equivalent</p>
</span></dd></dl></div></div><div class="doclet" id="-getNormal"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.getNormal()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L466-L478">src/spatial/math.js#L466-L478</a></div><span class="markdown"><p>Calculates a new right-handed unit vector that is perpendicular to the line created by this and the passed vector.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">getNormal</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">])</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Vector2D} [result] </dt><dd><span class="markdown"><p>An optional parameter to save the result in</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} the new normal vector</p>
</span></dd></dl></div></div><div class="doclet" id="-isZero"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.isZero()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L484-L495">src/spatial/math.js#L484-L495</a></div><span class="markdown"><p>Determines if this vector is equal to <0,0></p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Boolean} </span><span class="sig-noun">isZero</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Boolean} true if this vector is equal to <0,0></p>
</span></dd></dl></div></div><div class="doclet" id="-magnitude"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.magnitude()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L500-L511">src/spatial/math.js#L500-L511</a></div><span class="markdown"><p>Calculates the magnitude of this vector.
Note: Function objects in JavaScript already have a &#39;length&#39; member, hence the use of magnitude instead.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">magnitude</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} the magnitude of this vector</p>
</span></dd></dl></div></div><div class="doclet" id="-magnitudeSq"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.magnitudeSq()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L516-L528">src/spatial/math.js#L516-L528</a></div><span class="markdown"><p>Calculates the square of the magnitude of this vector.
This function avoids calculating the square root, thus being slightly faster than .magnitude( ).</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">magnitudeSq</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} the square of the magnitude of this vector</p>
</span></dd></dl></div><div><h4>See Also</h4><ul class="see-also-list"><li><a href="#-magnitude">.magnitude</a></li></ul></div></div><div class="doclet" id="-multiply"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.multiply()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L533-L544">src/spatial/math.js#L533-L544</a></div><span class="markdown"><p>Multiplies this vector by the passed vector</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">multiply</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} this vector after multiplying</p>
</span></dd></dl></div></div><div class="doclet" id="-negate"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.negate()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L551-L561">src/spatial/math.js#L551-L561</a></div><span class="markdown"><p>Negates this vector (ie. &lt;-x,-y&gt;)</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">negate</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} this vector after negation</p>
</span></dd></dl></div></div><div class="doclet" id="-normalize"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.normalize()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L568-L579">src/spatial/math.js#L568-L579</a></div><span class="markdown"><p>Normalizes this vector (scales the vector so that its new magnitude is 1)
For vectors where magnitude is 0, <1,0> is returned.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">normalize</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} this vector after normalization</p>
</span></dd></dl></div></div><div class="doclet" id="-perpendicular"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.perpendicular()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L447-L460">src/spatial/math.js#L447-L460</a></div><span class="markdown"><p>Calculates a new vector that is perpendicular to this vector.
The perpendicular vector has the same magnitude as this vector and is obtained by a counter-clockwise rotation of 90° of this vector.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">perpendicular</span></span><span class="sig-seperator">([</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">])</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} [result] </dt><dd><span class="markdown"><p>An optional parameter to save the result in</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} the perpendicular vector</p>
</span></dd></dl></div></div><div class="doclet" id="-scale"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.scale()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L595-L608">src/spatial/math.js#L595-L608</a></div><span class="markdown"><p>Scales this vector by the passed amount(s)
If scalarY is omitted, scalarX is used for both axes</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">scale</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Number</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Number</span></span><span class="sig-seperator">])</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Number} scalarX </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Number} [scalarY] </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} this after scaling</p>
</span></dd></dl></div></div><div class="doclet" id="-scaleToMagnitude"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.scaleToMagnitude()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L619-L630">src/spatial/math.js#L619-L630</a></div><span class="markdown"><p>Scales this vector such that its new magnitude is equal to the passed value.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">scaleToMagnitude</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Number</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Number} mag </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} this vector after scaling</p>
</span></dd></dl></div></div><div class="doclet" id="-setValues"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.setValues()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L638-L651">src/spatial/math.js#L638-L651</a></div><span class="markdown"><p>Sets the values of this vector using a passed vector or pair of numbers.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">setValues</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">setValues</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Number</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Number</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Number|Vector2D} x </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Number} y </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} this vector after setting of values</p>
</span></dd></dl></div></div><div class="doclet" id="-subtract"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.subtract()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L664-L675">src/spatial/math.js#L664-L675</a></div><span class="markdown"><p>Subtracts the passed vector from this vector.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">subtract</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{vector2D} this vector after subtracting</p>
</span></dd></dl></div></div><div class="doclet" id="-toString"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.toString()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L682-L692">src/spatial/math.js#L682-L692</a></div><span class="markdown"><p>Returns a string representation of this vector.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{String} </span><span class="sig-noun">toString</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{String}</p>
</span></dd></dl></div></div><div class="doclet" id="-translate"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.translate()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L697-L710">src/spatial/math.js#L697-L710</a></div><span class="markdown"><p>Translates (moves) this vector by the passed amounts.
If dy is omitted, dx is used for both axes.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">translate</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Number</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Number</span></span><span class="sig-seperator">])</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Number} dx </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Number} [dy] </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} this vector after translating</p>
</span></dd></dl></div></div><div class="doclet" id="-tripleProduct"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.tripleProduct()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/6998fc9e5dd81ac253023ad85232404c696484e8/src/spatial/math.js#L721-L737">src/spatial/math.js#L721-L737</a></div><span class="markdown"><p>Calculates the triple product of three vectors.
triple vector product = b(a•c) - a(b•c)</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">tripleProduct</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun"></span></span><span class="sig-seperator">[</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">])</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} a </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Vector2D} b </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Vector2D} c </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Vector2D} [result] </dt><dd><span class="markdown"><p>An optional parameter to save the result in</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} the triple product as a new vector</p>
</span></dd></dl></div></div></div></div></div></div>
			
		</div>
	</div>
	<div class="clearer"></div>
	<div id="footer">
		<div id="contact">
			<a href="https://groups.google.com/forum/#!forum/craftyjs">
				<img src="/images/google.png" />
				google groups</a>
			<a href="mailto:starwed@gmail.com">
				<img src="/images/email.png" />
				starwed@gmail.com</a>
			<a href="https://github.com/craftyjs/Crafty">
				<img src="/images/github.png" />
				github</a>
		</div>
		<ul>
			<li><a href="/">Home</a></li>
				<li><a href="/getting-started/">Getting started</a></li>
				<li><a href="/documentation/">Documentation</a></li>
				<li><a href="/api/">API</a></li>
				<li><a href="https://groups.google.com/forum/#!forum/craftyjs">Forum</a></li>
				<li><a href="/components/">Modules</a></li>
				<li class="emph"><a href="/#install">Download</a></li>
		</ul>
		<p>
			&copy; Crafty 2010-2015. Crafty is distributed under the <a href="http://en.wikipedia.org/wiki/MIT_License">MIT License</a>.
		</p>
	</div>
</div>
</body>
</html>
